<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="ykf">
    <title>work练习</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
</html>
<script>
    function work(name,isMale,birthdate){
        this.name = name;
        this.isMale = isMale;
        this.birthdate = birthdate;
    }
    work.prototype.salary = 10000;
    work.prototype.eat = function(food){
        console.log(this.name+'吃了'+food);
    }
    work.prototype.sleep = function(hours){
        console.log(this.name+'睡了'+hours+'小时');
    }
    work.prototype.play = function(game){
        console.log(this.name+'玩'+game);
    }
    work.prototype.study = function(course){
        console.log(this.name+'学习了'+course);
    }
    work.prototype.Work = function(task){
        console.log(this.name+'找到了'+task+'工作');
    }

    var tom = new work('Tom','true','1995');

    Object.defineProperty(tom,'age',{
        set:function(val){
            if(val<0){
                return; 
        }
        var today = new Date();
        this.birthdate = today.getFullYear() - val;
    },
    get:function(){
        var today = new Date();
        return today.getFullYear() - this.dirthdate;
    }
        
    })

    var age = tom.age;

    tom.eat('西瓜');
    tom.sleep('16');
    tom.play('捉迷藏');
    tom.study('政治');
    tom.Work('搬砖');
    console.log('age='+age);
    console.log(tom.name);
    console.log(tom.isMale);
    console.log(tom.birthdate);
</script>